home *** CD-ROM | disk | FTP | other *** search
- Path: garden.csc.calpoly.edu!not-for-mail
- From: dstubbs@garden.csc.calpoly.edu (Dan Stubbs)
- Newsgroups: comp.lang.c
- Subject: Re: level order binary search
- Date: 29 Mar 1996 08:57:18 -0800
- Organization: Cal Poly, San Luis Obispo
- Message-ID: <4jh4pe$ef4@garden.csc.calpoly.edu>
- References: <4jf9cd$p4d@aphex.direct.ca>
- NNTP-Posting-User: dstubbs@garden.csc.calpoly.edu
-
- In article <4jf9cd$p4d@aphex.direct.ca>,
- Ed Toivanen <etoivane@direct.ca> wrote:
- >What is the algorithm for a level order search of a binary tree?
- >Knuth leaves it as an "exercise for the reader". Peachy.
- >
- >
- >Thanks, Ed
- >
-
- A level order traverse (or search) looks at the root, then all
- nodes at level 2, then all nodes at level 3, and so on. In general
- a node at level k is processed after all nodes at level k-1 and
- before all nodes at level k+1.
-
- The algorithm to do this is the following:
-
- Put the root node in a queue.
- while the queue is not empty
- remove a node from the queue and process it.
- put the children of the node just processed in the queue.
- end while
-
- This is similar to the usual pre, in, and post order traversals
- except that a queue is used instead of a stack.
-
-
-